<?php

namespace Admin\Controller;

use Think\Controller;
class EntryController  extends Controller
{
    //登录界面
     public function login(){
         if(IS_POST){
            $code=I('post.code');
             //验证验证码
             $res=$this->check_verify($code);
            if(!$res){
                $this->error('对不起验证码不正确');exit;
            }
             $pass=md5(I('post.password'));
             $username=I('post.username');
             //验证用户名和密码
             if($data=M('user')->where("username='$username'")->find()){
                if((M('user')->where("username='$username'")->getField('password'))==$pass){
                    session('username',$data['uid']);
                    session('uid',$username);
                    $this->success('登录成功',U('admin/index/index'));exit;
                }else{
                    $this->error('密码不正确');die;
                }
             }else{
                 $this->error('用户不存在');die;
             };
         };
        $this->display();
     }
    //验证码
    public function code(){
        $Verify = new \Think\Verify();
        $Verify->entry();
    }
//    验证验证码
    private function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }
}